from goods.models import GoodsCategory

# 面包屑 , 获得商品类型
def get_breadcrumb(category):

    breadcrumb = {
        'cat1':'',
        'cat2':'',
        'cat3':'',
    }
    # 第一级数据主键为空
    if category.parent == None:
        breadcrumb['cat1'] = category

    # 三级数据是最后一级 , 没有数据绑定该数据 , 也就是说 , 没有数据的parent_id 是他的主键ID
    elif GoodsCategory.objects.filter(parent_id = category.id).count() == 0:
        cat2 = category.parent
        breadcrumb['cat1'] = cat2.parent
        breadcrumb['cat2'] = cat2
        breadcrumb['cat3'] = category

    else:
        breadcrumb['cat1'] = category.parent
        breadcrumb['cat2'] = category

    return breadcrumb



